<?php

function collate(array $arr, $key)
{
    $res = array();
    foreach ($arr as $value) {
        $keyValue = $value[$key];
        if (!isset($res[$keyValue])) $res[$keyValue] = array();
        $res[$keyValue][] = $value;
    }
    return $res;
}

function rekey(array $arr, $key)
{
    $res = array();
    foreach ($arr as $value) {
        $keyValue = $value[$key];
        $res[$keyValue] = $value;
    }
    return $res;
}